home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
aie8911.zip
/
BACK.ARI
< prev
next >
Wrap
Text File
|
1989-08-27
|
4KB
|
144 lines
%%%%%%%%%%%%%%%%%%%% end auto gened decs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- visible do_goal / 1.
:- extrn zzz_displayed / 1 : interp.
/************************* do_goal / 1 *************************************/
/*
executes a Prolog goal, using stubs as well as code
*/
% if a stub is there and it
% should be used (e.g. no Prolog code
% for process, use the stub
do_goal( Goal ) :-
% is there a stub for the Goal
has_stub( Goal, Frame ),
% should the stub be used?
use_the_stub_q( Frame),
!,
% then definitely use the stub
do_stub( Frame).
% If the goal is user-defined to
% fail, then make it fail (this
% lets the user explore the specified
% system)
do_goal( Goal ) :-
call( failing_goal( Goal)),
!,
fail.
% If the goal is defined in Prolog
% source code, then
% interpret it using the definition
% of Prolog
do_goal( Goal) :-
% Is the goal defined in Prolog code?
defined_as_prolog_goal( Goal ),
% display goal purpose from stub
display_goal_purpose( Goal ),
% log_write( $Goal = $), log_write(Goal),
% log_nl,
% get body of rule defining Goal
clause( Goal, Body),
% log_write( $Body = $), log_write(Body),
% log_nl,
% execute rule body
do_body( Body).
% Execute goals defined by Prolog system
% code
do_goal( Goal) :-
% Make sure there is no source code
% definition
not defined_as_prolog_goal( Goal ),
% Try the goal using Prolog system
% procedures
call( Goal ).
/************************* do_goal helpers *********************************/
% Is a goal defined as source code?
defined_as_prolog_goal( Term ) :-
clause( Term, _),
!.
% do_body executes Prolog rule bodies
% Is a goal defined as source code?
do_body( true ) :- !.
% Execute 'ands' of subgoals
% in rule bodies
do_body( ( H , Rest) ) :-
!,
do_and( H, Rest).
% Execute a single goal, by calling
% do_goal
do_body( Term) :-
do_goal( Term).
% do_and executes 'ands' of goals
do_and( Head , Rest) :-
% Try the first goal
do_goal( Head),
% Try the other goals
do_body( Rest).
/************************* display_goal_purpose ****************************/
display_goal_purpose( Goal ) :-
display_this_goal_q( Goal),
display_goal_hlpr( Goal),
!.
display_goal_purpose( _ ).
display_goal_hlpr( Goal) :-
has_stub( Goal, Frame ),
!,
display_purpose( Frame ).
display_goal_hlpr( Goal) :-
log_write($Executing $),
log_write( Goal),
log_write($.$),
log_nl.
display_this_goal_q( Goal) :-
functor( Goal, Name, Arity),
display_this_functor( Name / Arity),
!.
display_this_functor( Functor ) :-
call( zzz_displayed( Functor)).
display_this_functor( Name / _ ) :-
display_this_functor( Name ),
!.
/*********************** test for do_goal ******************************
test :-
do_goal( goal( X, Y)).
goal(X, Y) :-
foo(X),
ho(X,Y),
log_write(X),
log_nl,
log_write(Y).
foo(1).
foo(2).
ho( 2,3).
failing_goal( log_write(3)).
********************* end of file ***************************************/